﻿package com.widget.util
{
    import com.translator.comms.IComm;
    import com.translator.comms.ICommState;

    /**
     * Static class pertaining to what Version of a game we are playing
     */
    public class Version
    {
        /**
         * Dungeons & Dragons 3.5
         */
        public static const DnD_35:String = "D&D 3.5";

        /**
         * Dungeons & Dragons 4
         */
        public static const DnD_4:String  = "D&D 4";


        /**
         * Data key for current version
         */
        private static const VERSION_KEY:String = "Version";


        /**
         * Return the current Vedrsion based on the CommState
         * @param commState Current state
         * @return Current version (a public constant from this class)
         */
        public static function GetVersion(commState:ICommState):String
        {
            return commState.GetValue(VERSION_KEY, DnD_4);
        }

        /**
         * Return whether Version has even been specified
         * @param commState Current state
         * @return Whether Version has been specified or not
         */
        public static function IsVersionSpecified(commState:ICommState):Boolean
        {
            return (null != commState.GetValue(VERSION_KEY, null));
        }

        /**
         * Set current Version
         * @param comm Communication layer
         * @param version Version you want to set things to
         */
        public static function SetVersion(comm:IComm, version:String):void
        {
            var delta:Object = new Object();
            delta[VERSION_KEY] = version;
            comm.SubmitDelta(delta);
        }

        /**
         * Return what Versions are available
         * @return An array of versions
         */
        public static function GetVersionData():Array
        {
            return [DnD_4, DnD_35];
        }
    }
}